package com.ushine.design.design.c_behavioral_pattern.d_iterator.b_example;

import java.util.ArrayList;
import java.util.List;

public class Client {
    public static void main(String[] args) {
        List<Object> prList = new ArrayList<Object>();

        prList.add("倚天剑");
        prList.add("屠龙刀");
        prList.add("断肠草");
        prList.add("葵花宝典");
        prList.add("金刚经");
        prList.add("四十二章经");

        AbstractObjectList list;
        AbstractIterator iterator;

        list = new ProductList(prList);
        iterator = list.createIterator();

        System.err.println("正向遍历：");
        while (!iterator.isLast()) {
            System.out.println(iterator.getNextItem() + ",");
            iterator.next();
        }

        System.out.println();
        System.out.println("---------------------------");
        System.out.println();

        System.out.println("逆向遍历：");
        while (!iterator.isFirst()) {
            System.out.println(iterator.getPreviousItem() + ",");
            iterator.previous();

        }
    }
}
